package com.mgiandia.library.jpadao;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import com.mgiandia.library.dao.ItemDAO;
import com.mgiandia.library.domain.core.Item;

class ItemJpaDAO extends GenericJpaDAO<Item> implements ItemDAO {

    public Item find(int itemNo) {
        Item item = JPAUtil.getCurrentEntityManager().find(Item.class, itemNo);
        return item;
    }

    public List<Item> findAll() {
        CriteriaBuilder builder = JPAUtil.getEntityManagerFactory().getCriteriaBuilder();
        CriteriaQuery<Item> criteria = builder.createQuery( Item.class );
        Root<Item> item = criteria.from( Item.class );
        criteria.select(item);
        return JPAUtil.getCurrentEntityManager().createQuery(criteria).getResultList();     
    }

   

}
